package com.heima.common.exception;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.sun.tools.internal.ws.processor.generator.CustomExceptionGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ExceptionCatch  {
    @ExceptionHandler(value = Exception.class)
    public ResponseResult CatchException (Exception e){e.printStackTrace();
        log.info("不可预知异常,错误:{}",e.getMessage());
        return  ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);


    }
    @ExceptionHandler(value = CustomException.class)
    public  ResponseResult exceptionCatch (CustomException e){
        e.printStackTrace();
        log.info("可知异常,错误:{}",e.getMessage());
        return ResponseResult.errorResult(e.getAppHttpCodeEnum());
    }

}
